package com.gitee.huanminabc.utils_test;

import com.gitee.huanminabc.utils_tools.thirdparty.config.ThirdpartyConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Slf4j
@EnableDubbo
@EnableSwagger2

@SpringBootApplication(
        //排除不需要的自动装配
        exclude = {
        // DataSourceAutoConfiguration取消自动装配数据源, 我们自己配置数据源
        DataSourceAutoConfiguration.class,
        //第三方对接配置
        ThirdpartyConfig.class
})
@MapperScan({"com.gitee.huanminabc.**.mapper"})
@EnableAspectJAutoProxy(proxyTargetClass = true) //开启AOP的动态代理,这样可以不用实现接口就能使用AOP
@EnableTransactionManagement
//扫描服务和工具包
@ComponentScan(
        basePackages = {"com.gitee.huanminabc.**"},
        excludeFilters = {
                //取消一些@Value注解的类和InitializingBean @PostConstruct注解的类 这些会被强制加载
                @ComponentScan.Filter(
                        type = FilterType.REGEX,
                        pattern = {
                                "com.gitee.huanminabc.utils_tools.thirdparty.*"
                        })
        }
)
//需要自定义线程池的时候打开
//@Import({ThreadFactoryConfig.class})
public class TestMainApplication {


    public static void main(String[] args) {
        try {
            SpringApplication app = new SpringApplication(TestMainApplication.class);
            app.setBannerMode((Banner.Mode.OFF));
            Environment env = app.run(args).getEnvironment();
            app.addListeners();


            log.info("\n\t----------------------------------------------------------\n\t" +
                            "Application '{}' is running! Access Urls:\n\t" +
                            "Local: \t\t{}://{}:{}\n\t" +
                            "Swagger API:{}://{}:{}/swagger-ui.html\n\t" +
                            "----------------------------------------------------------",
                    env.getProperty("spring.application.name"),
                    "http",
                    "127.0.0.1",
                    env.getProperty("server.port"),
                    "http",
                    "127.0.0.1",
                    env.getProperty("server.port"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



}